﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FineUI;
using System.Data;

namespace EmptyProjectNet40_FineUI
{
    public partial class WebForm1 : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindGrid();
            }
        }


        #region BindGrid

        public string GetGender(object o)
        {
            return "男";
        }

        private void BindGrid()
        {
            // 1.设置总项数（特别注意：数据库分页一定要设置总记录数RecordCount）
            Grid1.RecordCount = GetTotalCount();

            // 2.获取当前分页数据
            DataTable table = GetPagedDataTable(Grid1.PageIndex, Grid1.PageSize);

            // 3.绑定到Grid
            Grid1.DataSource = table;
            Grid1.DataBind();
        }

        /// <summary>
        /// 模拟返回总项数
        /// </summary>
        /// <returns></returns>
        private int GetTotalCount()
        {
            return 3;// DataSourceUtil.GetDataTable2().Rows.Count;
        }

        /// <summary>
        /// 模拟数据库分页（实际项目中请直接使用SQL语句返回分页数据！）
        /// </summary>
        /// <returns></returns>
        private DataTable GetPagedDataTable(int pageIndex, int pageSize)
        {
           // DataTable source = null;// DataSourceUtil.GetDataTable2();

            DataTable dt = new DataTable();//创建表
            dt.Columns.Add("ID", typeof(Int32));//添加列
            dt.Columns.Add("Name", typeof(String));
            dt.Columns.Add("birthday", typeof(String));
            dt.Columns.Add("Gender", typeof(Int32));
            dt.Rows.Add(new object[] { 1, "张三","1967-01-21", 20 });//添加行
            dt.Rows.Add(new object[] { 2, "李四", "1955-11-11", 25 });
            dt.Rows.Add(new object[] { 3, "王五", "1949-08-05", 30 });


            DataTable paged = dt.Clone();// source.Clone();

            int rowbegin = pageIndex * pageSize;
            int rowend = (pageIndex + 1) * pageSize;
            if (rowend > dt.Rows.Count)
            {
                rowend = dt.Rows.Count;
            }

            for (int i = rowbegin; i < rowend; i++)
            {
                paged.ImportRow(dt.Rows[i]);
            }

            return paged;
        }

        #endregion

        #region Events

        protected void Button1_Click(object sender, EventArgs e)
        {
            //labResult.Text = HowManyRowsAreSelected(Grid1);
            this.Window1.Hidden = false;
        }

        protected void rbl3_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (rbl3.SelectedValue == "已确诊")
            {
                //this.frYQZ.Hidden = false;
                //this.frWQZ.Hidden = true;
            }
            else
            {
                //this.frYQZ.Hidden = true;
                //this.frWQZ.Hidden = false;
            }
        }

        protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
        {
            //Grid1.PageIndex = e.NewPageIndex;

            BindGrid();
        }

        protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
        {
            //临床症状
            if (e.CommandName == "Action1")
            {
                Window2.Hidden = false;
            }

            //过去疾病史
            if (e.CommandName == "Action2")
            {
                Window3.Hidden = false;
            }

            if (e.CommandName == "Action3")
            {
                Window4.Hidden = false;
            }
        }
        #endregion

    }
}